function batchSelect(selectEl){
	var isChecked = $(selectEl).attr('checked');
	var elements = $('body').find('input[type=checkbox][name!=List_Selected2]');
	if(isChecked){
		elements.attr('checked',true);
	}else{
		elements.attr('checked',false);
	}
}
function batchDelete(targetEventId,formId,url){
	$('#'+targetEventId).click(function(){
		var selectedEls = $('body').find('input[type=checkbox][checked=true][name!=List_Selected2]');
		if(selectedEls.length<1){
			alert('请选择!');
			return;
		}
		if(confirm('确认删除吗？')){
			$('#'+formId).attr('action',url);
			$('#'+formId).submit();
		}
	});
}
function addOperate(targetEventId,url){
	$('#'+targetEventId).click(function(){
		window.location.href = url;
	});
}
function updateOperate(targetEventId,url){
	$('#'+targetEventId).click(function(){
		var checkedBox = $('body').find('input[type=checkbox][checked=true][name!=List_Selected2]');
		if(checkedBox.length>1){
			alert('只能选一个!');
			return;
		}
		if(checkedBox.length<1){
			alert('请选择');
			return;
		}
		window.location.href = url + '?id=' + checkedBox.val();
	});
}

function isAllSelected(formId){
	var selectAllBtn = $('#'+formId).find('input[type=checkbox][name=List_Selected2]');
	var listEls = $('#'+formId).find('input[type=checkbox][name!=List_Selected2]');
	listEls.click(function(){
		var isSelectAllBtnChecked = true;
		for(var i=0;i<listEls.length;i++){
			if(!$(listEls[i]).attr('checked')){
				selectAllBtn.attr('checked', false);
				return;
			}
		}
		selectAllBtn.attr('checked', true);
	});
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

//菜单点击下拉展示
$(document).ready(function () {
	$('li.mainlevel').click(function(){
		$(this).find('ul').slideDown();//you can give it a speed
	});
	$('li.mainlevel').mouseleave(function(){
		$(this).find('ul').slideUp("fast");
	});
	
	$("#div1").hover(function(){
		$("#tab1").show();
		$("#tab2").hide();
	});
	$("#div2").hover(function(){
		$("#tab2").show();
		$("#tab1").hide();
	});
	
	$("#btn_left").click(function(){
		$("#left").toggle();
		});
});

//body预加载图片
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
//鼠标移上去替换图片
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

/**
 * 删除附件
 */
var deletePicIndex = 0;
function deleteAtt(selfEl,picId, formId, beanName){
	if(!picId || !formId || !beanName){
		$(selfEl).parent().remove();
		return;
	}
	selfEl = $(selfEl).parent();
	form = $('#'+formId);
	var picElIsDelete = $('<input type="hidden" />');
	picElIsDelete.attr('name',beanName+'.toDeletePics['+ deletePicIndex++ +']');
	picElIsDelete.attr('value',picId);
	form.append(picElIsDelete);
	selfEl.remove();
}
/**
 * 添加附件
 */
var newPicindex = 0;
function addAttachment(selfEl, beanName){
	var picDiv = $('<div></div>');
	var attEl = $('<input type="file" />');
	attEl.attr('name',beanName+'.attachments['+ newPicindex++ +'].file');
	var delBtn = $('<a style="color:red" href="javascript:void(0)" onclick="javascript:deleteAtt(this)">&nbsp;X</a>')[0];
	$(picDiv).append(attEl);
	$(attEl).after(delBtn);
	$(selfEl).after(picDiv);
}

function updateAttachment(selfEl, beanName){
	if(attSize > 0){
	    alert("标题图片只能添加一张。");
	    return;
	}
	addAttachment(selfEl, beanName);
	attSize = attSize + 1;
}

function deleteAttAndSize(selfEl,picId, formId, beanName){
	deleteAtt(selfEl,picId, formId, beanName);	
	attSize = attSize - 1;
}